package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.subscribebean.ListBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/7.
 * 猜你喜欢adapter
 */
public class SubInterestAdapter extends RecyclerView.Adapter<SubInterestAdapter.MyViewHolder> {
    private List<ListBean> list;

    private Context context;
    public void setList(List<ListBean> list) {
        this.list = list;
    }
    private OnItemClickListener listener;
    //点击事件的设置
    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }
    public SubInterestAdapter( Context context) {
        this.context = context;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_sub_interest,null));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        //数据的加载
        Glide.with(context).load(list.get(position).getPic()).into(holder.ivItemInterest);
        holder.tvItemInterest.setText(list.get(position).getTitle());
        holder.iconItemInterest.setImageURI(list.get(position).getCat().getIcon());
        holder.tvItemCatname.setText(list.get(position).getCat().getName());
        holder.tvItemPublishTime.setText(list.get(position).getPublishTime());
        if (listener != null) {
            //点击
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    listener.onItemClick(holder.itemView, pos);
                }
            });
            //长按
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    listener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }


    @Override
    public int getItemCount() {
        return list.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.iv_item_interest)
        ImageView ivItemInterest;
        @InjectView(R.id.tv_item_interest)
        TextView tvItemInterest;
        @InjectView(R.id.icon_item_interest)
        SimpleDraweeView iconItemInterest;
        @InjectView(R.id.tv_item_catname)
        TextView tvItemCatname;
        @InjectView(R.id.tv_item_publish_time)
        TextView tvItemPublishTime;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }


}
